import { reactive } from 'vue';

interface SnackbarState {
  show: boolean;
  type: 'success' | 'error';
  message: string;
}

// 全局snackbar状态
export const snackbarState = reactive<SnackbarState>({
  show: false,
  type: 'success',
  message: ''
});

// 显示成功消息
export function showSuccess(message: string, duration: number = 3000) {
  snackbarState.show = true;
  snackbarState.type = 'success';
  snackbarState.message = message;
  
  setTimeout(() => {
    snackbarState.show = false;
  }, duration);
}

// 显示错误消息
export function showError(message: string, duration: number = 3000) {
  snackbarState.show = true;
  snackbarState.type = 'error';
  snackbarState.message = message;
  
  setTimeout(() => {
    snackbarState.show = false;
  }, duration);
}

// 隐藏snackbar
export function hideSnackbar() {
  snackbarState.show = false;
}